@extends('backstage.layout.master')
@section('title', '添加优惠券')
@section('style')
    <!-- page specific plugin styles -->
    <link rel="stylesheet" href="/assets/css/jquery-ui-1.10.3.custom.min.css"/>
    <link rel="stylesheet" href="/assets/css/chosen.css"/>
    <link rel="stylesheet" href="/assets/css/datepicker.css"/>
    <link rel="stylesheet" href="/assets/css/bootstrap-timepicker.css"/>
    <link rel="stylesheet" href="/assets/css/daterangepicker.css"/>
    <link rel="stylesheet" href="/assets/css/colorpicker.css"/>
    <!-- fonts -->
    <style type="text/css">
        input.button {
            padding: 5px 15px 5px;
            margin: 2px 2px;
            border: none;
            background: #24a0d6;
            color: #FFF;
            cursor: pointer;
        }
        #fav_num{
            width: 20%;
        }
        #form-field-select-2 {
            width: 50%;
            margin-right: 6%;
        }
    </style>
@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="/backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="/backstage/coupons/couponslist">优惠券 </a>
            </li>
            <li>
                <a href="/backstage/coupons/addcoupons">发放优惠券</a>
            </li>
        </ul><!-- .breadcrumb -->
    </div>

    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                    <h1>
                        优惠券
                        <small>
                            <i class="icon-double-angle-right"></i>
                            发放优惠券
                        </small>
                    </h1>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="alert alert-info">
                            <i class="icon-hand-right"></i>
                            <!-- 信息-->
                        </div>
                        <div class="space-4"></div>
                        <div class="form-horizontal">
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 优惠券兑换码</label>

                                <div class="col-sm-4">
                                    <textarea class="form-control" name="coupon_id" id="coupon_id"
                                              placeholder="优惠券兑换码,多个兑换码以 ','号区分开，例：AAA,BBB"></textarea>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline" id="name_warn"></div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" >用户编号</label>
                                <div class="col-sm-4">
                                    <textarea class="form-control" name="user_id" id="user_id"
                                              placeholder="用户编号,多个用户编号以 ','号区分开，例：AAA,BBB"></textarea>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"id="channel_id_error"></div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group ">
                                <label class="col-sm-3 control-label no-padding-right " for="form-field-1">是否推送</label>
                                <div class="col-sm-4">
                                    <select name="is_push" class="form-control" id="is_push">
                                        <option value="0">否</option>
                                        <option value="1">是</option>
                                    </select>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"></div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" > 推送标题 </label>

                                <div class="col-sm-4">
                                    <textarea class="form-control" name="title" id="title"
                                              placeholder="推送标题"></textarea>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"id="coupon_num_warn"></div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" > 手机通知栏内容 </label>

                                <div class="col-sm-4">
                                    <textarea class="form-control" name="message_phone" id="message_phone"
                                              placeholder="手机通知栏内容"></textarea>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"id="coupon_num_warn"></div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" > APP内消息推送内容 </label>

                                <div class="col-sm-4">
                                    <textarea class="form-control" name="message" id="message"
                                              placeholder="APP内消息推送内容"></textarea>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"id="coupon_num_warn"></div>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            <div class="clearfix form-actions">
                                <div class="col-md-offset-3 col-md-9">
                                    <button class="btn btn-info" type="button" onclick="send()">
                                        <i class="icon-ok bigger-110"></i>
                                        发放
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div><!-- /.col -->
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
<script src="backstage/assets/js/date-time/bootstrap-datepicker.min.js"></script>
<script src="backstage/assets/js/date-time/bootstrap-timepicker.min.js"></script>
<script src="backstage/assets/js/date-time/moment.min.js"></script>
<script src="backstage/assets/js/date-time/daterangepicker.min.js"></script>
<script type="text/javascript">
 function send(){
    var user_id   = $("#user_id").val();
    var coupon_id = $("#coupon_id").val();
    var is_push   = $("#is_push option:selected").val();
    var title     = $("#title").val();
    var msg_phone = $("#message_phone").val();
    var msg       = $("#message").val();
    $.ajax({
        type: "POST",
        url: "/backstage/coupons/coupon-to-user",
        data: {
                'user_id':user_id,
                'coupon_id':coupon_id,
                'is_push':is_push,
                'title':title,
                'message_phone':msg_phone,
                'message':msg,
            },
        success: function (re) {
            if (re.state == 'M00000'){
                swal('成功','','success');
                return;
            }
            swal(re.message, '', 'warning');
        }, error: function () {
            swal({
                title: "系统繁忙！",
                text: "",
                type: "error",
                timer:2000
            });
        }
    });
 }
</script>
@stop
